import {reactive} from "vue";
import {IModelRef} from "@/views/Pretty/Main/EditForm/types";
import {Rule} from "ant-design-vue/es/form";

export const modelRef = reactive<IModelRef>({
  "mobile": "",
  "price": 0,
  "level": 1,
  "status": 1,
});
const validateMobile = async (_rule: Rule, value: string) => {
  const reg = /^[1][3-9][\d]{9}$/
  if (value === '') {
    return Promise.reject("请输入手机号")
  } else {
    const flag = reg.test(value)
    if (flag) {
      return Promise.resolve()
    } else {
      return Promise.reject("手机号码格式有误")
    }
  }
};
export const rulesRef = reactive<Record<string, Rule[]>>({
  "mobile": [{
    required: true,
    validator: validateMobile,
    trigger: "change"
  }],
  "price": [{
    required: true
  }],
  "level": [{
    required: true, message: '请选择等级'
  }],
  "status": [{
    required: true, message: '请选择状态'
  }],
})
